package org.cuijq.thinking.in.spring.dependency.injection;

import java.util.List;
import java.util.Set;
import javax.jws.soap.SOAPBinding.Use;
import org.cuijq.thinking.in.spring.ioc.domain.SuperUser;
import org.cuijq.thinking.in.spring.ioc.domain.User;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;

/**
 * @author by CuiJQ
 * @Classname XmlDepencySetterInjectionDemo
 * @Description XmlDepencySetterInjectionDemo Description
 * @Date 2021/6/29 9:04
 */
public class LayAnnotationDepencyFieldInjectionDemo {

  @Autowired
  private User user;
  @Autowired
  //@UserGroup
  private ObjectProvider<User> objectProviderUsers;

  @Autowired
  //@UserGroup
  private ObjectProvider<Set<User>> objectSetProviderUsers;

  public static void main(String[] args) {
    //创建BeanFactory 容器
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
    //注册
    applicationContext.register(LayAnnotationDepencyFieldInjectionDemo.class);

    XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(applicationContext);
    String xmlResourcePath = "classpath:/META-INF/dependency-lookuo-context.xml";
    beanDefinitionReader.loadBeanDefinitions(xmlResourcePath);

    applicationContext.refresh();

    LayAnnotationDepencyFieldInjectionDemo demo = applicationContext.getBean(LayAnnotationDepencyFieldInjectionDemo.class);
    
    User user = demo.user;
    System.out.println(user);

//    ObjectProvider<User> users = demo.objectProviderUsers;
//    users.forEach(user1 -> System.out.println(user1.toString()));
    ObjectProvider<Set<User>> sets = demo.objectSetProviderUsers;
    System.out.println(sets.getObject());
    sets.forEach(user1 -> System.out.println(user1.toString()));



    applicationContext.close();
  }
//
//  @Bean
//  @Qualifier("user")
//  User user() {
//    User user = new User();
//    user.setId(1L);
//    user.setName("xxx");
//    return user;
//  }
//
//  ;
//
//  @Bean
//  @UserGroup()
//  User user1() {
//    User user = new User();
//    user.setId(2L);
//    user.setName("xxxxGroup");
//    return user;
//  }
//
//  ;
//
//
//  @Bean
//  @Qualifier("superUser")
//  SuperUser user2() {
//    SuperUser user = new SuperUser();
//    user.setId(2L);
//    user.setName("superUserXxxxGroup");
//    return user;
//  }
//
//  @Bean
//  public UserHolder userHolder(User user) {
//    return new UserHolder(user2());
//  }
}
